/******************************************************************************* 
 *  Copyright 2007 Amazon Technologies, Inc.  
 *  Licensed under the Apache License, Version 2.0 (the "License"); 
 *  
 *  You may not use this file except in compliance with the License. 
 *  You may obtain a copy of the License at: http://aws.amazon.com/apache2.0
 *  This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
 *  CONDITIONS OF ANY KIND, either express or implied. See the License for the 
 *  specific language governing permissions and limitations under the License.
 * ***************************************************************************** 
 *    __  _    _  ___ 
 *   (  )( \/\/ )/ __)
 *   /__\ \    / \__ \
 *  (_)(_) \/\/  (___/
 * 
 *  Amazon ECS CSharp Library
 *  API Version: 2007-07-16
 *  Generated: Thu Aug 02 10:15:38 PDT 2007 
 * 
 */

using System;
using System.Xml.Serialization;
using System.Collections.Generic;
using System.Text;


namespace Amazon.ECS.Model
{
    [XmlTypeAttribute(Namespace = "http://webservices.amazon.com/AWSECommerceService/2007-07-16")]
    [XmlRootAttribute(Namespace = "http://webservices.amazon.com/AWSECommerceService/2007-07-16", IsNullable = false)]
    public class Shipment
    {
    
        private String conditionField;

        private String deliveryMethodField;

        private  ShipmentItems shipmentItemsField;
        private  ShipmentPackages packagesField;

        /// <summary>
        /// Gets and sets the Condition property.
        /// </summary>
        [XmlElementAttribute(ElementName = "Condition")]
        public String Condition
        {
            get { return this.conditionField ; }
            set { this.conditionField= value; }
        }



        /// <summary>
        /// Sets the Condition property
        /// </summary>
        /// <param name="condition">Condition property</param>
        /// <returns>this instance</returns>
        public Shipment WithCondition(String condition)
        {
            this.conditionField = condition;
            return this;
        }



        /// <summary>
        /// Checks if Condition property is set
        /// </summary>
        /// <returns>true if Condition property is set</returns>
        public Boolean IsSetCondition()
        {
            return  this.conditionField != null;

        }


        /// <summary>
        /// Gets and sets the DeliveryMethod property.
        /// </summary>
        [XmlElementAttribute(ElementName = "DeliveryMethod")]
        public String DeliveryMethod
        {
            get { return this.deliveryMethodField ; }
            set { this.deliveryMethodField= value; }
        }



        /// <summary>
        /// Sets the DeliveryMethod property
        /// </summary>
        /// <param name="deliveryMethod">DeliveryMethod property</param>
        /// <returns>this instance</returns>
        public Shipment WithDeliveryMethod(String deliveryMethod)
        {
            this.deliveryMethodField = deliveryMethod;
            return this;
        }



        /// <summary>
        /// Checks if DeliveryMethod property is set
        /// </summary>
        /// <returns>true if DeliveryMethod property is set</returns>
        public Boolean IsSetDeliveryMethod()
        {
            return  this.deliveryMethodField != null;

        }


        /// <summary>
        /// Gets and sets the ShipmentItems property.
        /// </summary>
        [XmlElementAttribute(ElementName = "ShipmentItems")]
        public ShipmentItems ShipmentItems
        {
            get { return this.shipmentItemsField ; }
            set { this.shipmentItemsField = value; }
        }



        /// <summary>
        /// Sets the ShipmentItems property
        /// </summary>
        /// <param name="shipmentItems">ShipmentItems property</param>
        /// <returns>this instance</returns>
        public Shipment WithShipmentItems(ShipmentItems shipmentItems)
        {
            this.shipmentItemsField = shipmentItems;
            return this;
        }



        /// <summary>
        /// Checks if ShipmentItems property is set
        /// </summary>
        /// <returns>true if ShipmentItems property is set</returns>
        public Boolean IsSetShipmentItems()
        {
            return this.shipmentItemsField != null;
        }




        /// <summary>
        /// Gets and sets the Packages property.
        /// </summary>
        [XmlElementAttribute(ElementName = "Packages")]
        public ShipmentPackages Packages
        {
            get { return this.packagesField ; }
            set { this.packagesField = value; }
        }



        /// <summary>
        /// Sets the Packages property
        /// </summary>
        /// <param name="packages">Packages property</param>
        /// <returns>this instance</returns>
        public Shipment WithPackages(ShipmentPackages packages)
        {
            this.packagesField = packages;
            return this;
        }



        /// <summary>
        /// Checks if Packages property is set
        /// </summary>
        /// <returns>true if Packages property is set</returns>
        public Boolean IsSetPackages()
        {
            return this.packagesField != null;
        }






        /// <summary>
        /// XML fragment representation of this object
        /// </summary>
        /// <returns>XML fragment for this object.</returns>
        /// <remarks>
        /// Name for outer tag expected to be set by calling method. 
        /// This fragment returns inner properties representation only
        /// </remarks>


        protected internal String ToXMLFragment() {
            StringBuilder xml = new StringBuilder();
            if (IsSetCondition()) {
                xml.Append("<Condition>");
                xml.Append(EscapeXML(this.Condition));
                xml.Append("</Condition>");
            }
            if (IsSetDeliveryMethod()) {
                xml.Append("<DeliveryMethod>");
                xml.Append(EscapeXML(this.DeliveryMethod));
                xml.Append("</DeliveryMethod>");
            }
            if (IsSetShipmentItems()) {
                ShipmentItems  shipmentItems = this.ShipmentItems;
                xml.Append("<ShipmentItems>");
                xml.Append(shipmentItems.ToXMLFragment());
                xml.Append("</ShipmentItems>");
            } 
            if (IsSetPackages()) {
                ShipmentPackages  packages = this.Packages;
                xml.Append("<Packages>");
                xml.Append(packages.ToXMLFragment());
                xml.Append("</Packages>");
            } 
            return xml.ToString();
        }

        /**
         * 
         * Escape XML special characters
         */
        private String EscapeXML(String str) {
            StringBuilder sb = new StringBuilder();
            foreach (Char c in str)
            {
                switch (c) {
                case '&':
                    sb.Append("&amp;");
                    break;
                case '<':
                    sb.Append("&lt;");
                    break;
                case '>':
                    sb.Append("&gt;");
                    break;
                case '\'':
                    sb.Append("&#039;");
                    break;
                case '"':
                    sb.Append("&quot;");
                    break;
                default:
                    sb.Append(c);
                    break;
                }
            }
            return sb.ToString();
        }




    }

}